package changedb;


import java.awt.image.BufferedImage;
import java.io.File;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.UIManager;

/**
 *
 *
 * @author Ben Goodwin
 * @version 2.0 16/09/2011
 */
public class MemberFrame extends javax.swing.JFrame {

    private MembersList ml;
    private boolean edit;
    private final Member m;

    /** Creates new form MemberFrame */
    public MemberFrame(MembersList ml) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        m = null;
        edit = false;
        this.ml = ml;
        initComponents();
        pic.setIcon(new ImageIcon(System.getProperty("user.dir") + "/images/default.jpg"));
        setVisible(true);
    }

    public MemberFrame(MembersList ml, Member m) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        edit = true;
        this.ml = ml;
        this.m = m;
        initComponents();
        editFrame((ArrayList) m.getDetails());
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        details = new javax.swing.JPanel();
        nameLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        firstname = new javax.swing.JTextField();
        dd = new javax.swing.JTextField();
        email = new javax.swing.JTextField();
        mobile = new javax.swing.JTextField();
        mum = new javax.swing.JTextField();
        dad = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        lastname = new javax.swing.JTextField();
        type = new javax.swing.JComboBox();
        mm = new javax.swing.JTextField();
        yyyy = new javax.swing.JTextField();
        school = new javax.swing.JComboBox();
        address1 = new javax.swing.JTextField();
        address2 = new javax.swing.JTextField();
        town = new javax.swing.JTextField();
        postcode = new javax.swing.JTextField();
        pic = new javax.swing.JLabel();
        sosNo = new javax.swing.JLabel();
        sosNum = new javax.swing.JTextField();
        save = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        medical = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        other = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Member Details");
        setResizable(false);

        details.setMinimumSize(new java.awt.Dimension(200, 0));

        nameLabel.setFont(new java.awt.Font("Verdana", 0, 12));
        nameLabel.setText("NAME");

        jLabel1.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel1.setText("DOB:");

        jLabel2.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel2.setText("EMAIL");

        jLabel3.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel3.setText("MOBILE");

        jLabel4.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel4.setText("ADDRESS");

        jLabel5.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel5.setText("MOTHER");

        jLabel6.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel6.setText("FATHER");

        jLabel7.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel7.setText("TYPE");

        firstname.setFont(new java.awt.Font("Verdana", 0, 14));
        firstname.setForeground(new java.awt.Color(153, 153, 153));
        firstname.setText("first name");
        firstname.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        firstname.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                firstnameFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                firstnameFocusLost(evt);
            }
        });

        dd.setFont(new java.awt.Font("Verdana", 0, 14));
        dd.setForeground(new java.awt.Color(153, 153, 153));
        dd.setText("dd");
        dd.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        dd.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                ddFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                ddFocusLost(evt);
            }
        });

        email.setFont(new java.awt.Font("Verdana", 0, 10));
        email.setForeground(new java.awt.Color(153, 153, 153));
        email.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        email.setText("email");
        email.setAutoscrolls(false);
        email.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        email.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                emailFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                emailFocusLost(evt);
            }
        });

        mobile.setFont(new java.awt.Font("Verdana", 0, 14));
        mobile.setForeground(new java.awt.Color(153, 153, 153));
        mobile.setText("mobile");
        mobile.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        mobile.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                mobileFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                mobileFocusLost(evt);
            }
        });

        mum.setFont(new java.awt.Font("Verdana", 0, 14));
        mum.setForeground(new java.awt.Color(153, 153, 153));
        mum.setText("mother's name");
        mum.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        mum.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                mumFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                mumFocusLost(evt);
            }
        });

        dad.setFont(new java.awt.Font("Verdana", 0, 14));
        dad.setForeground(new java.awt.Color(153, 153, 153));
        dad.setText("father's name");
        dad.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        dad.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                dadFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                dadFocusLost(evt);
            }
        });

        jLabel8.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel8.setText("SCHOOL");

        lastname.setFont(new java.awt.Font("Verdana", 0, 14));
        lastname.setForeground(new java.awt.Color(153, 153, 153));
        lastname.setText("last name");
        lastname.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        lastname.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                lastnameFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                lastnameFocusLost(evt);
            }
        });

        type.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Leader", "Change", "Ignite" }));

        mm.setFont(new java.awt.Font("Verdana", 0, 14));
        mm.setForeground(new java.awt.Color(153, 153, 153));
        mm.setText("mm");
        mm.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        mm.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                mmFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                mmFocusLost(evt);
            }
        });

        yyyy.setFont(new java.awt.Font("Verdana", 0, 14));
        yyyy.setForeground(new java.awt.Color(153, 153, 153));
        yyyy.setText("yyyy");
        yyyy.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        yyyy.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                yyyyFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                yyyyFocusLost(evt);
            }
        });

        school.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Please select:", "Langton Girls", "Langton Boys", "Archbishops", "Chaucer", "St. Anselms", "Canterbury High", "St. Edmunds", "Kent College", "Barton Court", "UKC", "CCCU", "Canterbury College", "Other", "None" }));

        address1.setFont(new java.awt.Font("Verdana", 0, 14));
        address1.setForeground(new java.awt.Color(153, 153, 153));
        address1.setText("address line 1");
        address1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        address1.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                address1FocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                address1FocusLost(evt);
            }
        });

        address2.setFont(new java.awt.Font("Verdana", 0, 14));
        address2.setForeground(new java.awt.Color(153, 153, 153));
        address2.setText("address line 2");
        address2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        address2.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                address2FocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                address2FocusLost(evt);
            }
        });

        town.setFont(new java.awt.Font("Verdana", 0, 14));
        town.setForeground(new java.awt.Color(153, 153, 153));
        town.setText("town/city");
        town.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        town.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                townFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                townFocusLost(evt);
            }
        });

        postcode.setFont(new java.awt.Font("Verdana", 0, 14));
        postcode.setForeground(new java.awt.Color(153, 153, 153));
        postcode.setText("postcode");
        postcode.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        postcode.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                postcodeFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                postcodeFocusLost(evt);
            }
        });

        pic.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        pic.setMaximumSize(new java.awt.Dimension(150, 200));
        pic.setMinimumSize(new java.awt.Dimension(150, 200));
        pic.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                picMouseClicked(evt);
            }
        });

        sosNo.setFont(new java.awt.Font("Verdana", 0, 12));
        sosNo.setText("SOS No.");

        sosNum.setFont(new java.awt.Font("Verdana", 0, 14));
        sosNum.setForeground(new java.awt.Color(153, 153, 153));
        sosNum.setText("emergency telephone");
        sosNum.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        sosNum.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                sosNumFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                sosNumFocusLost(evt);
            }
        });

        save.setText("Save");
        save.setMaximumSize(new java.awt.Dimension(60, 23));
        save.setMinimumSize(new java.awt.Dimension(60, 23));
        save.setPreferredSize(new java.awt.Dimension(60, 23));
        save.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveActionPerformed(evt);
            }
        });

        cancel.setText("Cancel");
        cancel.setMaximumSize(new java.awt.Dimension(60, 23));
        cancel.setMinimumSize(new java.awt.Dimension(60, 23));
        cancel.setPreferredSize(new java.awt.Dimension(60, 23));
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("Verdana", 0, 12));
        jLabel9.setText("MEDICAL");

        medical.setFont(new java.awt.Font("Verdana", 0, 14));
        medical.setForeground(new java.awt.Color(153, 153, 153));
        medical.setText("medical information");
        medical.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        medical.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                medicalFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                medicalFocusLost(evt);
            }
        });

        other.setColumns(20);
        other.setFont(new java.awt.Font("Verdana", 0, 14));
        other.setForeground(new java.awt.Color(153, 153, 153));
        other.setLineWrap(true);
        other.setRows(5);
        other.setText("Any other information");
        other.setWrapStyleWord(true);
        other.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusGained(java.awt.event.FocusEvent evt) {
                otherFocusGained(evt);
            }
            public void focusLost(java.awt.event.FocusEvent evt) {
                otherFocusLost(evt);
            }
        });
        other.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                otherKeyTyped(evt);
            }
        });
        jScrollPane1.setViewportView(other);
        other.getAccessibleContext().setAccessibleParent(this);

        javax.swing.GroupLayout detailsLayout = new javax.swing.GroupLayout(details);
        details.setLayout(detailsLayout);
        detailsLayout.setHorizontalGroup(
            detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(detailsLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(detailsLayout.createSequentialGroup()
                        .addComponent(pic, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(detailsLayout.createSequentialGroup()
                                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(nameLabel)
                                    .addComponent(jLabel1)
                                    .addComponent(jLabel3)
                                    .addComponent(jLabel2)
                                    .addComponent(sosNo)
                                    .addComponent(jLabel6)
                                    .addComponent(jLabel5))
                                .addGap(15, 15, 15)
                                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(mum, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                                    .addComponent(email, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                                    .addComponent(mobile, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                                    .addGroup(detailsLayout.createSequentialGroup()
                                        .addComponent(dd, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(mm, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(yyyy, javax.swing.GroupLayout.PREFERRED_SIZE, 56, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(detailsLayout.createSequentialGroup()
                                        .addComponent(firstname, javax.swing.GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lastname, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(sosNum, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)
                                    .addComponent(dad, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 251, Short.MAX_VALUE)))
                            .addGroup(detailsLayout.createSequentialGroup()
                                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel9)
                                    .addComponent(jLabel8))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(medical, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                                    .addComponent(school, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(detailsLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(address2)
                            .addComponent(address1, javax.swing.GroupLayout.DEFAULT_SIZE, 172, Short.MAX_VALUE)
                            .addComponent(town)
                            .addComponent(postcode, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, detailsLayout.createSequentialGroup()
                        .addComponent(save, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cancel, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        detailsLayout.setVerticalGroup(
            detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(detailsLayout.createSequentialGroup()
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pic, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(detailsLayout.createSequentialGroup()
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(nameLabel)
                            .addComponent(firstname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lastname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(type, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(yyyy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(mm, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(dd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(mobile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(12, 12, 12)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sosNo)
                            .addComponent(sosNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(mum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(dad, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(medical, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(school, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(detailsLayout.createSequentialGroup()
                        .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(address1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(address2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(town, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(postcode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(detailsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(save, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(details, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(details, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-510)/2, (screenSize.height-472)/2, 510, 472);
    }// </editor-fold>//GEN-END:initComponents

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        int answer = JOptionPane.showConfirmDialog(null, "Are you sure you want to cancel?",
                "Cancel?", JOptionPane.YES_NO_OPTION);
        if (answer == JOptionPane.YES_OPTION) {
            this.dispose();
        }
    }//GEN-LAST:event_cancelActionPerformed

    private void saveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveActionPerformed
        if (!firstname.getText().equals("first name") && !lastname.getText().equals("last name")) {
            Member m2 = new Member((String) type.getSelectedItem(), firstname.getText(), lastname.getText(),
                    email.getText(), mobile.getText(), dd.getText(), mm.getText(), yyyy.getText(), address1.getText(),
                    address2.getText(), town.getText(), postcode.getText(), mum.getText(),
                    dad.getText(), (String) school.getSelectedItem(), sosNum.getText(), medical.getText(), other.getText());
            try {
                ImageIcon picture = (ImageIcon) pic.getIcon();
                String s = picture.getDescription();
                if (!s.contains("default")) {
                    BufferedImage i = ImageIO.read(new File(s));
                    ImageIO.write(i, "jpg", new File(System.getProperty("user.dir") + "/images/" + firstname.getText().toLowerCase().trim() + lastname.getText().toLowerCase().trim() + ".jpg"));
                }
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error saving picture, using default.",
                        "Save of Picture Failed", JOptionPane.ERROR_MESSAGE);
            }

            try {
                ArrayList<Member> al = (ArrayList) ml.getMembers();
                if (edit) {
                    int answer = JOptionPane.showConfirmDialog(null, "Member \"" + m
                            + "\" already exists.\nDo you want to replace the existing member?",
                            "Member already exists", JOptionPane.YES_NO_OPTION);
                    if (answer == JOptionPane.YES_OPTION) {
                        al.remove(m);
                        al.add(m2);
                    }
                    ml.setList(al);
                } else {
                    al.add(m2);
                    ml.setList(al);
                }
                JOptionPane.showMessageDialog(null, "Saved member: " + m2
                        + " successfully.", "Save successful", JOptionPane.INFORMATION_MESSAGE);
                this.dispose();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error saving member: " + m2,
                        "Save Failed", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            JOptionPane.showMessageDialog(null, "A member must have a name...",
                    "Nameless member?", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_saveActionPerformed

    private void firstnameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_firstnameFocusGained
        if (firstname.getText().equals("first name")) {
            firstname.setText("");
            firstname.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_firstnameFocusGained

    private void lastnameFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_lastnameFocusGained
        if (lastname.getText().equals("last name")) {
            lastname.setText("");
            lastname.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_lastnameFocusGained

    private void ddFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ddFocusGained
        if (dd.getText().equals("dd")) {
            dd.setText("");
            dd.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_ddFocusGained

    private void mmFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mmFocusGained
        if (mm.getText().equals("mm")) {
            mm.setText("");
            mm.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_mmFocusGained

    private void yyyyFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_yyyyFocusGained
        if (yyyy.getText().equals("yyyy")) {
            yyyy.setText("");
            yyyy.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_yyyyFocusGained

    private void emailFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_emailFocusGained
        if (email.getText().equals("email")) {
            email.setText("");
            email.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_emailFocusGained

    private void mobileFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mobileFocusGained
        if (mobile.getText().equals("mobile")) {
            mobile.setText("");
            mobile.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_mobileFocusGained

    private void mumFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mumFocusGained
        if (mum.getText().equals("mother's name")) {
            mum.setText("");
            mum.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_mumFocusGained

    private void dadFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dadFocusGained
        if (dad.getText().equals("father's name")) {
            dad.setText("");
            dad.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_dadFocusGained

    private void address1FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_address1FocusGained
        if (address1.getText().equals("address line 1")) {
            address1.setText("");
            address1.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_address1FocusGained

    private void address2FocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_address2FocusGained
        if (address2.getText().equals("address line 2")) {
            address2.setText("");
            address2.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_address2FocusGained

    private void townFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_townFocusGained
        if (town.getText().equals("town/city")) {
            town.setText("");
            town.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_townFocusGained

    private void postcodeFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_postcodeFocusGained
        if (postcode.getText().equals("postcode")) {
            postcode.setText("");
            postcode.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_postcodeFocusGained

    private void firstnameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_firstnameFocusLost
        if (firstname.getText().equals("")) {
            firstname.setForeground(new java.awt.Color(153, 153, 153));
            firstname.setText("first name");
        }
    }//GEN-LAST:event_firstnameFocusLost

    private void lastnameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_lastnameFocusLost
        if (lastname.getText().equals("")) {
            lastname.setForeground(new java.awt.Color(153, 153, 153));
            lastname.setText("last name");
        }
    }//GEN-LAST:event_lastnameFocusLost

    private void ddFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_ddFocusLost
        if (dd.getText().equals("")) {
            dd.setForeground(new java.awt.Color(153, 153, 153));
            dd.setText("dd");
        }
    }//GEN-LAST:event_ddFocusLost

    private void mmFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mmFocusLost
        if (mm.getText().equals("")) {
            mm.setForeground(new java.awt.Color(153, 153, 153));
            mm.setText("mm");
        }
    }//GEN-LAST:event_mmFocusLost

    private void yyyyFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_yyyyFocusLost
        if (yyyy.getText().equals("")) {
            yyyy.setForeground(new java.awt.Color(153, 153, 153));
            yyyy.setText("yyyy");
        }
    }//GEN-LAST:event_yyyyFocusLost

    private void emailFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_emailFocusLost
        if (email.getText().equals("")) {
            email.setForeground(new java.awt.Color(153, 153, 153));
            email.setText("email");
        }
    }//GEN-LAST:event_emailFocusLost

    private void mobileFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mobileFocusLost
        if (mobile.getText().equals("")) {
            mobile.setForeground(new java.awt.Color(153, 153, 153));
            mobile.setText("mobile");
        }
    }//GEN-LAST:event_mobileFocusLost

    private void mumFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_mumFocusLost
        if (mum.getText().equals("")) {
            mum.setForeground(new java.awt.Color(153, 153, 153));
            mum.setText("mother's name");
        }
    }//GEN-LAST:event_mumFocusLost

    private void dadFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_dadFocusLost
        if (dad.getText().equals("")) {
            dad.setForeground(new java.awt.Color(153, 153, 153));
            dad.setText("father's name");
        }
    }//GEN-LAST:event_dadFocusLost

    private void address1FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_address1FocusLost
        if (address1.getText().equals("")) {
            address1.setForeground(new java.awt.Color(153, 153, 153));
            address1.setText("address line 1");
        }
    }//GEN-LAST:event_address1FocusLost

    private void address2FocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_address2FocusLost
        if (address2.getText().equals("")) {
            address2.setForeground(new java.awt.Color(153, 153, 153));
            address2.setText("address line 2");
        }
    }//GEN-LAST:event_address2FocusLost

    private void townFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_townFocusLost
        if (town.getText().equals("")) {
            town.setForeground(new java.awt.Color(153, 153, 153));
            town.setText("town/city");
        }
    }//GEN-LAST:event_townFocusLost

    private void postcodeFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_postcodeFocusLost
        if (postcode.getText().equals("")) {
            postcode.setForeground(new java.awt.Color(153, 153, 153));
            postcode.setText("postcode");
        }
    }//GEN-LAST:event_postcodeFocusLost

    private void picMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_picMouseClicked
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Exception e) {
        }
        ImageIcon currentPic;
        JFileChooser openPic = new JFileChooser();
        openPic.setFileFilter(new JPGFilter());
        int choose = openPic.showOpenDialog(null);
        if (choose == JFileChooser.APPROVE_OPTION) {
            try {
                currentPic = new ImageIcon(openPic.getSelectedFile().getPath());
                currentPic.setDescription(openPic.getSelectedFile().getPath());
            } catch (Exception e) {
                currentPic = new ImageIcon(System.getProperty("user.dir") + "/images/default.jpg");
                currentPic.setDescription("Default");
            }
        } else {
            currentPic = new ImageIcon(System.getProperty("user.dir") + "/images/default.jpg");
            currentPic.setDescription("Default");
        }
        pic.setIcon(currentPic);
    }//GEN-LAST:event_picMouseClicked

    private void sosNumFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sosNumFocusGained
        if (!edit) {
            sosNum.setText("");
            sosNum.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_sosNumFocusGained

    private void sosNumFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_sosNumFocusLost
        if (sosNum.getText().equals("")) {
            sosNum.setForeground(new java.awt.Color(153, 153, 153));
            sosNum.setText("emergency telephone");
        }
    }//GEN-LAST:event_sosNumFocusLost

    private void medicalFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_medicalFocusGained
        if (!edit) {
            medical.setText("");
            medical.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_medicalFocusGained

    private void medicalFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_medicalFocusLost
        if (medical.getText().equals("")) {
            medical.setForeground(new java.awt.Color(153, 153, 153));
            medical.setText("medical information");
        }
    }//GEN-LAST:event_medicalFocusLost

    private void otherFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_otherFocusGained
        if (!edit) {
            other.setText("");
            other.setForeground(new java.awt.Color(0, 0, 0));
        }
    }//GEN-LAST:event_otherFocusGained

    private void otherFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_otherFocusLost
        if (other.getText().equals("")) {
            other.setForeground(new java.awt.Color(153, 153, 153));
            other.setText("Any other information");
        }
    }//GEN-LAST:event_otherFocusLost

    private void otherKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_otherKeyTyped
        if(evt.getKeyCode() == java.awt.event.KeyEvent.VK_TAB) other.transferFocus();
    }//GEN-LAST:event_otherKeyTyped

    private void editFrame(ArrayList<String> m) {
        File f = new File(System.getProperty("user.dir") + "/images/" + m.get(1).toLowerCase().trim()
                + m.get(2).toLowerCase().trim() + ".jpg");
        ImageIcon picture;
        if (f.exists()) {
            picture = new ImageIcon(System.getProperty("user.dir") + "/images/" + m.get(1).toLowerCase().trim()
                    + m.get(2).toLowerCase().trim() + ".jpg");
        } else {
            picture = new ImageIcon(System.getProperty("user.dir") + "/images/default.jpg");
        }
        pic.setIcon(picture);
        type.setSelectedItem(m.get(0));
        firstname.setText(m.get(1));
        firstname.setForeground(new java.awt.Color(0, 0, 0));
        lastname.setText(m.get(2));
        lastname.setForeground(new java.awt.Color(0, 0, 0));
        email.setText(m.get(3));
        email.setForeground(new java.awt.Color(0, 0, 0));
        mobile.setText(m.get(4));
        mobile.setForeground(new java.awt.Color(0, 0, 0));
        dd.setText(m.get(5));
        dd.setForeground(new java.awt.Color(0, 0, 0));
        mm.setText(m.get(6));
        mm.setForeground(new java.awt.Color(0, 0, 0));
        yyyy.setText(m.get(7));
        yyyy.setForeground(new java.awt.Color(0, 0, 0));
        address1.setText(m.get(8));
        address1.setForeground(new java.awt.Color(0, 0, 0));
        address2.setText(m.get(9));
        address2.setForeground(new java.awt.Color(0, 0, 0));
        town.setText(m.get(10));
        town.setForeground(new java.awt.Color(0, 0, 0));
        mum.setText(m.get(12));
        mum.setForeground(new java.awt.Color(0, 0, 0));
        dad.setText(m.get(13));
        dad.setForeground(new java.awt.Color(0, 0, 0));
        postcode.setText(m.get(11));
        postcode.setForeground(new java.awt.Color(0, 0, 0));
        school.setSelectedItem(m.get(14));
        sosNum.setText(m.get(15));
        sosNum.setForeground(new java.awt.Color(0, 0, 0));
        medical.setText(m.get(16));
        medical.setForeground(new java.awt.Color(0, 0, 0));
        other.setText(m.get(17));
        other.setForeground(new java.awt.Color(0, 0, 0));
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                MemberFrame memberFrame = new MemberFrame(new MembersList());
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField address1;
    private javax.swing.JTextField address2;
    private javax.swing.JButton cancel;
    private javax.swing.JTextField dad;
    private javax.swing.JTextField dd;
    private javax.swing.JPanel details;
    private javax.swing.JTextField email;
    private javax.swing.JTextField firstname;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField lastname;
    private javax.swing.JTextField medical;
    private javax.swing.JTextField mm;
    private javax.swing.JTextField mobile;
    private javax.swing.JTextField mum;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextArea other;
    private javax.swing.JLabel pic;
    private javax.swing.JTextField postcode;
    private javax.swing.JButton save;
    private javax.swing.JComboBox school;
    private javax.swing.JLabel sosNo;
    private javax.swing.JTextField sosNum;
    private javax.swing.JTextField town;
    private javax.swing.JComboBox type;
    private javax.swing.JTextField yyyy;
    // End of variables declaration//GEN-END:variables
}
